<template>
  <div class="detail-enterprise">
    <header class="add-header">
      <el-page-header content="查看企业" @back="$router.back()" />
    </header>

    <main class="add-main">
      <div class="head form-container">
<div class="title">企业信息</div>
        <el-descriptions :column="2">
          <el-descriptions-item label="企业名称">{{form.name}}</el-descriptions-item>
          <el-descriptions-item label="法人">{{form.legalPerson}}</el-descriptions-item>
          <el-descriptions-item label="注册地址">{{form.registeredAddress}}</el-descriptions-item>
          <el-descriptions-item label="所在行业">{{form.industryName}}</el-descriptions-item>
          <el-descriptions-item label="营业执照">
            <img :src="form.businessLicenseUrl" alt="营业执照图片" style="max-width: 100%; max-height: 200px;">
          </el-descriptions-item>
        </el-descriptions>
      </div>
      <div class="body form-container">
<div class="title">联系人信息</div>
<el-descriptions :column="2">
          <el-descriptions-item label="企业联系人">{{form.contact}}</el-descriptions-item>
          <el-descriptions-item label="联系电话">{{form.contactNumber}}</el-descriptions-item>
        </el-descriptions>
      </div>
      <div class="form-container">


        <div class="title">租赁记录</div>
        <div class="table-container">
          <el-table :data="form.rent" style="width: 100%" border>
            <el-table-column type="index" label="序号" width="50" />
            <el-table-column prop="name" label="租赁楼宇" width="180" />
            <el-table-column label="合同状态" width="180">
              <template >
        <el-tag
          :type="contractState.value"
          disable-transitions>{{contractState.name}}</el-tag>
      </template>
              </el-table-column>
            <el-table-column label="租赁起止时间" width="280">
              <template #default="{ row }">
                {{ row.startTime }} - {{ row.endTime }}
              </template>
            </el-table-column>

            <el-table-column label="租赁合同(点击预览)">
              <template #default="{ row }">
                <el-button type="text">
                  <a :href="`${previewURL}${row.contractUrl}`" target="_blank">
                    {{ row.contractName }}
                  </a>
                </el-button>
              </template>
            </el-table-column>

            <el-table-column prop="createTime" label="录入时间" />
            <el-table-column prop="address" label="操作">
              <template #default="{ row }">
                <el-button type="text">
                  <a :href="row.contractUrl">合同下载</a></el-button
                >
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </main>
  </div>
</template>

<script>
import { getEnterpriseDetail } from "@/api/park";
export default {
  data() {
    return {
      contractState:{},
      form: {},
      previewURL: 'https://view.officeapps.live.com/op/view.aspx?src='
    };
  },
  created() {
    this.getDetail();
  },
  methods: {
    async getDetail() {
      const res = await getEnterpriseDetail(this.$route.query.id);
      this.form = res.data;
      const time = +new Date();
      if(time<+new Date(this.form.rent[0].startTime)){
        this.contractState={name:"待生效",value:"success"}
        return 
      }else if(time>+new Date(this.form.rent[0].endTime)){
        this.contractState={name:"已到期",value:"danger"}
        return 
      }else{
        this.contractState={name:"生效中",value:"primary"}
        return 
      }
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-descriptions-item__label{
  color:gray;
}
.body.form-container{
  height: 130px;
}
::v-deep .el-descriptions__body{
  padding-left: 10%;
}
::v-deep .el-table__header-wrapper th {
  background-color: #f4f6f8;
}
.detail-enterprise {
  background-color: #f4f6f8;
  height: 100vh;

  .add-header {
    display: flex;
    align-items: center;
    padding: 0 20px;
    height: 64px;
    background-color: #fff;

    .left {
      span {
        margin-right: 4px;
      }
      .arrow {
        cursor: pointer;
      }
    }

    .right {
      text-align: right;
    }
  }

  .add-main {
    background: #f4f6f8;
    padding: 20px 130px;

    .form-container {
      background-color: #fff;
      margin-bottom: 20px;
      .title {
        height: 60px;
        line-height: 60px;
        padding-left: 20px;
      }
    }
    .table-container {
      padding: 20px;
    }
    .preview {
      img {
        width: 100px;
      }
    }
  }
}
</style>
